package pl.oczadly.jabberclient.mainwindow.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import pl.oczadly.jabberclient.addcontact.view.AddContactView;
import pl.oczadly.jabberclient.addcontact.view.IAddContactView;
import pl.oczadly.jabberclient.utils.Utils;

public class ContactsView {

	JList list;
	
	public ContactsView( JList model ) {
		this.list = model;
	}
	
	public void addContactsView( JMenuBar menuBar ) {
		JMenu contactsMenu = new JMenu( Utils.CONTACTS_MENU );
		
		JMenuItem addContactItem = new JMenuItem( Utils.ADD_CONTACT );
		addContactItem.addActionListener( new AddContactListener() );
		
		JMenuItem removeContactItem = new JMenuItem( Utils.REMOVE_CONTACT );
		
		JMenu exportMenu = new JMenu( Utils.EXPORT_CONTACTS );
		JMenuItem exportToFile = new JMenuItem( Utils.EXPORT_CONTACTS_TO_FILE );
		JMenuItem exportToServer = new JMenuItem( Utils.EXPORT_CONTACTS_TO_SERVER );
		
		exportMenu.add( exportToFile );
		exportMenu.add( exportToServer );
		
		JMenu importMenu = new JMenu( Utils.IMPORT_CONTACTS );
		JMenuItem importFromFile = new JMenuItem( Utils.IMPORT_CONTACTS_FROM_FILE );
		JMenuItem importFromServer = new JMenuItem( Utils.IMPORT_CONTACTS_FROM_SERVER );
		
		importMenu.add( importFromFile );
		importMenu.add( importFromServer );
		
		contactsMenu.add( addContactItem );
		contactsMenu.add( removeContactItem );
		contactsMenu.add( exportMenu );
		contactsMenu.add( importMenu );
		
		menuBar.add( contactsMenu );
	}
	
	private class AddContactListener implements ActionListener {
		public void actionPerformed( ActionEvent e ) {
			IAddContactView addContact = new AddContactView( list );
			addContact.createUI();
		}
	}
	
}
